package com.song.config;

import cn.hutool.core.collection.CollectionUtil;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.policy.DynamicTableRenderPolicy;
import com.deepoove.poi.policy.TableRenderPolicy;
import com.song.model.ServerTableData;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import java.util.List;
import java.util.Map;

public class ServerTablePolicy extends DynamicTableRenderPolicy {
    @Override
    public void render(XWPFTable xwpfTable, Object data) throws Exception {
        if (null == data){
            return;
        }
        ServerTableData serverTableData = (ServerTableData) data;
        List<RowRenderData> serverDataList = serverTableData.getServerDataList();
        List<Map<String, Object>> groupDataList = serverTableData.getGroupDataList();
        int mergeColumn = serverTableData.getMergeColumn();
        int columnLength = serverTableData.getColumnLength();
        if (CollectionUtil.isNotEmpty(serverDataList)){
            for (int i = 0; i < serverDataList.size(); i++) {
                XWPFTableRow xwpfTableRow = xwpfTable.insertNewTableRow(1);
                for (int j = 0; j < columnLength; j++) {
                    xwpfTableRow.createCell();
                }
                TableRenderPolicy.Helper.renderRow(xwpfTableRow, serverDataList.get(i));
            }
            for (int i = 0; i < serverDataList.size(); i++) {

            }
        }
    }
}
